// 访问值
var score: [String: Int] = ["Alice": 90, "Bob": 85, "Charlie": 95]
if let aliceScore = score["Alice"] {
    print("Alice's score is \(aliceScore)")
} else {
    print("Alice's score not found")
}
// 修改值
score["Alice"] = 95
print("Alice's new score is \(score["Alice"]!)")

// updateValue方法更新键的值，并返回旧值的可选类型
if let oldValue = score.updateValue(75, forKey: "Bob") {
    print("Bob's old score was \(oldValue)")
} else {
    print("Bob's score not found")
}

// 删除键值对
score["Charlie"] = nil
print("Charlie removed from scores")
print(score)

//删除键值对
if let removedValue = score.removeValue(forKey: "Bob") {
    print("Removed Bob's score: \(removedValue)")
} else {
    print("Bob's score not found")
}

// 清空字典
score.removeAll()
print("All scores removed")
print(score)
score["Bob"] = 85
print(score["Bob"]!)

// 默认值访问
// `subscript(default:)` 提供默认值，避免解包可选值
let count = score["Dave", default: 0]
print("Dave's score is \(count)")
